<template>
  <div class="mod-role" style="width:100%">
    <el-form
      :inline="true"
      label-width="120px"
      size="small"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item label="航班号：">
        <el-input v-model="dataForm.FLIGHT_NUM" placeholder="请输入 " clearable></el-input>
      </el-form-item>

      <el-form-item label="航班日期：">
        <el-date-picker
          style="width:200px"
          v-model="dataForm.FLIGHT_DATE"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="报告制作日期：">
        <el-date-picker
          v-model="dataForm.CREATE_TIME"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期"
          style="width:200px"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="始发地：">
        <el-input v-model="dataForm.FLIGHT_FROM" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item label="航司代码：">
        <el-input v-model="dataForm.endArea" placeholder="请输入" clearable></el-input>
      </el-form-item>

      <el-form-item label="航班状态：">
        <el-checkbox-group v-model="dataForm.STATUS">
          <el-checkbox label="111" name="type">已完成</el-checkbox>
          <el-checkbox label="1" name="type">未完成</el-checkbox>
          <el-checkbox label="作废" name="type">作废</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="库区状态：">
        <el-checkbox-group style="width:200px"  v-model="dataForm.options1V">
          <el-checkbox label="100,101,111,110" name="type4">已完成</el-checkbox>
          <el-checkbox label="001,010,011,1" name="type4">制作中</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="单证状态：">
        <el-checkbox-group style="width:200px" v-model="dataForm.options2V">
          <el-checkbox label="010,011,110,111" name="type2">已完成</el-checkbox>
          <el-checkbox label="001,101,100,1" name="type2">制作中</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="查看状态：">
        <el-checkbox-group style="width:200px"  v-model="dataForm.options3V">
          <el-checkbox label="001,011,101,111" name="type3">已完成</el-checkbox>
          <el-checkbox label="001,010,011,1" name="type3">制作中</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      
      <el-form-item style="padding-right:120px;float:right">
        <el-button v-if="isAuthBtnS('cha')" @click="getDataList()">查询</el-button>
        <el-button v-if="isAuthBtnS('add')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button
          v-if="isAuth('sys:role:delete')"
          type="danger"
          @click="deleteHandle()"
          :disabled="dataListSelections.length <= 0"
        >批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      size="small"
      stripe
      :data="dataList"
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
    >
      <!-- <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column> -->
      <el-table-column
        prop="REPORT_NUM"
        sortable
        min-width="100px"
        header-align="center"
        align="center"
        label="报告编号"
      ></el-table-column>
      <el-table-column
        prop="CREATE_TIME"
        header-align="center"
        show-overflow-tooltip
        align="center"
        min-width="100px"
        sortable
        label="报告时间"
      ></el-table-column>
      <!-- <el-table-column prop="positionId" header-align="center" align="center" label="制表人数"></el-table-column> -->
      <el-table-column sortable prop="FLIGHT_NUM" header-align="center" align="center" label="航班号"></el-table-column>
      <el-table-column
        sortable
        prop="FLIGHT_DATE"
        header-align="center"
        show-overflow-tooltip
        align="center"
        min-width="100px"
        label="航班日期"
      ></el-table-column>
      <el-table-column prop="FLIGHT_FROM" sortable header-align="center" align="center" label="始发地"></el-table-column>
      <el-table-column prop="FLIGHT_TO" sortable header-align="center" align="center" label="目的地"></el-table-column>
      <el-table-column
        prop="FLIGHT_STATUS_NAME"
        header-align="center"
        width="80"
        sortable
        align="center"
        label="状态"
      ></el-table-column>
      <el-table-column
        prop="USER_NAME1"
        sortable
        header-align="center"
        width="80"
        align="center"
        label="库区"
      ></el-table-column>
      <el-table-column
        prop="FLIGHT_STATUS_NAME1"
        header-align="center"
        sortable
        min-width="100px"
        align="center"
        label="库区状态"
      ></el-table-column>
      <el-table-column
        prop="USER_NAME2"
        header-align="center"
        sortable
        min-width="100px"
        align="center"
        label="单证"
      ></el-table-column>
      <el-table-column
        prop="FLIGHT_STATUS_NAME2"
        header-align="center"
        sortable
        min-width="100px"
        align="center"
        label="单证状态"
      ></el-table-column>
      <el-table-column
        prop="USER_NAME3"
        header-align="center"
        sortable
        min-width="100px"
        align="center"
        label="查询"
      ></el-table-column>
      <el-table-column
        prop="FLIGHT_STATUS_NAME3"
        header-align="center"
        sortable
        min-width="100px"
        align="center"
        label="查询状态"
      ></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="220" label="操作">
        <template slot-scope="scope">
          <el-button
            v-if="isAuthBtnS('extra1')||isAuthBtnS('extra2')||isAuthBtnS('extra3')   "
            type="primary"
            size="mini"
            @click="addOrUpdateHandle(scope.row.ID)"
          >修改</el-button>
          <el-button type="success" size="mini" @click="printPdf(scope.row.ID)">查看</el-button>
          <el-button v-if="isAuthBtnS('extra55')" size="mini" @click="downLoadPdf(scope.row.ID)">下载</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./internaladd";
export default {
  data() {
    return {
      qxlist: {},
      dataForm: {
        roleName: "",
        DEPARTMENT_ID: "",
        STATUS: [],
        FLIGHT_STATUS: [],
        type2: [],
        options1V: [],
        options2V: [],
        options3V: [],
        value: ""
      },
      dataList: [],

      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    };
  },
  components: { AddOrUpdate },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    isAuthBtnS(data) {
      return this.qxlist && this.qxlist[data] && this.qxlist[data] == "1"
        ? true
        : false;
    },
    getDataList() {
      this.dataListLoading = true;
      let FLIGHT_STATUS = this.dataForm.options1V.concat(
        this.dataForm.options2V,
        this.dataForm.options3V
      );
      this.$http({
        url: this.$http.adornUrl("/air/list"),
        method: "POST",
        data: this.$http.adornData({
          page: this.pageIndex,
          showCount: this.pageSize,
          FLIGHT_NUM: this.dataForm.FLIGHT_NUM,
          FLIGHT_DATE: this.dataForm.FLIGHT_DATE,
          CREATE_TIME: this.dataForm.CREATE_TIME,
          FLIGHT_FROM: this.dataForm.FLIGHT_FROM,
          DEPARTMENT_ID: this.dataForm.DEPARTMENT_ID,
          STATUS: this.dataForm.STATUS.join(","),
          FLIGHT_STATUS: FLIGHT_STATUS.join(",")
        })
      }).then(({ data }) => {
        if (data) {
          this.qxlist = Object.assign({}, this.qxList, data.QX);
          this.dataList = data.list;
          this.totalPage = data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      // this.$router.push({ name: "air/edit" });
      this.addOrUpdateVisible = true;
      console.log(id);
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id, this.qxlist);
      });
    },
    printPdf(id) {
      window.open(window.location.origin + "/aper/air/pdf/air?ID=" + id);
    },
    downLoadPdf(id) {
      this.$http({
        url: this.$http.adornUrl("/air/pdf/uploadpdf"),
        method: "post",
        data: this.$http.adornData({
          url: window.location.origin + "/aper/air/pdf/air?ID=" + id,
          fileUrl: id + ".pdf"
        })
      }).then(({ data }) => {
        if (data && data.result == 1) {
          window.open(data.url);
        } else {
          this.$message.error(data.message);
        }
      });
    },
    // 删除
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.dataListSelections.map(item => {
            return item.roleId;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          this.$http({
            url: this.$http.adornUrl("/sys/role/delete"),
            method: "post",
            data: this.$http.adornData(ids, false)
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.getDataList();
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => {});
    }
  }
};
</script>
<style lang="scss">
.mod-role {
  .el-checkbox {
    margin-right: 10px;
  }
  .el-checkbox:last-child {
    margin-right: 0;
  }
  .el-checkbox + .el-checkbox {
    margin: 0;
    margin-right: 10px;
  }
}
</style>
